package com.rk.admin.controller;
import com.rk.admin.aop.SystemControllerLog;
import com.rk.admin.domain.Briefinfo;
import com.rk.admin.service.BriefinfoService;
import com.rk.admin.tools.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Api(tags = "中心简介")
@CrossOrigin //前后端分离配置跨域访问
@RestController
@RequestMapping("/brief")
public class BriefinfoController {

    @Autowired
    private BriefinfoService briefinfoService;



    @ApiOperation("查询中心简介")
    @GetMapping("/info")
    public CommonResult find(){
        return CommonResult.success(briefinfoService.selectHomepage());
    }


    /**
     * 通过id修改中心简介
     */
    @ApiOperation("通过id修改中心简介")
    @SystemControllerLog(description = "修改中心简介")
    @PostMapping("/updatebyid")
    public CommonResult updatebyid(@RequestBody Briefinfo briefinfo){
        //设置修改时间
        briefinfo.setEdittime(new Date());
        Boolean flag = briefinfoService.updatebyid(briefinfo);

        if(flag){//如果修改成功
            return CommonResult.success(flag);
        }else {
            return CommonResult.failed("修改失败!");
        }
    }



    @ApiOperation(("分页查询中心简介"))
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "分页起始页码",required = true,example = "1"),
            @ApiImplicitParam(name = "limit",value = "每页数据条数",required = true,example = "5"),
            @ApiImplicitParam(name = "title",value = "文章标题",example = ""),
    })
    @GetMapping("/findPage")
    public CommonResult findPageBen(Integer page,Integer limit, String title){
        return CommonResult.success(briefinfoService.selectPage(page,limit,title));
    }
}
